package cn.com.utt.common.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import cn.com.utt.common.vo.Role;

public interface UserRoleMapper {
	
	@Insert("insert into user_role(rid,uid)values(#{rid},#{uid})")
	void save(@Param("rid")Integer rid,@Param("uid")Long uid);
	
	@Delete("delete from user_role where rid=#{rid} and uid=#{uid}")
	void delete(@Param("rid")Integer rid,@Param("uid")Long uid);
	
	@Select("select r.* from role r,user_role ur where ur.uid=#{uid} and ur.rid=r.id")
	List<Role> queryByUid(@Param("uid")Long uid);
	
	@Delete("delete from user_role where uid=#{uid}")
	void deleteByUid(@Param("uid")Long uid);
	
	@Delete({"<script>",
	    "delete ", 
	    "FROM `user_role`",
	    "WHERE ", 
	    "uid IN", 
	      "<foreach item='item' index='index' collection='uids'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	"</script>"})
	void deleteByUids(@Param("uids")List<Long> uids);
	
}
